# Maintainer: Diaz Devera Victor <vitronic2@gmail.com>
pkgname=fcron
pkgver=3.2.1
pkgrel=2
pkgdesc="periodical command scheduler for systems not always up"
url="http://fcron.free.fr/"
install="fcron.pre-install"
options="suid !check"
pkgusers="fcron"
pkggroups="fcron"
arch="all"
license="GPL"
makedepends="readline-dev perl"
subpackages="$pkgname-openrc $pkgname-pam::noarch $pkgname-doc"
source="http://fcron.free.fr/archives/${pkgname}-${pkgver}.src.tar.gz
	systab.orig
	fcron.initd"

_builddir="$srcdir"/${pkgname}-${pkgver}

prepare() {
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i;;
		esac
	done
}

build() {
	cd "$_builddir"
	./configure --prefix=/usr \
		--with-editor=/usr/bin/vi \
		--with-spooldir=/var/spool/fcron \
		--sysconfdir=/etc/fcron \
		--with-answer-all=no \
		--with-boot-install=no \
		--localstatedir=/var \
		--with-piddir=/run \
		--with-sendmail=no \
		--with-selinux=no \
		--with-systemdsystemunitdir=no
	make
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir/" install
	install -Dm775 ${srcdir}/fcron.initd ${pkgdir}/etc/init.d/fcron
	rm -r ${pkgdir}/var/run
	#for some reason it man/fr is not compressed, for that reason I erase
	rm -r ${pkgdir}/usr/share/man/fr
	install -Dm640 "${srcdir}/systab.orig" "${pkgdir}/var/spool/fcron/systab.orig"
}

pam() {
	cd "$_builddir"
	pkgdesc="PAM configuration file for fcron package."
	depends="fcron"
	mkdir $subpkgdir
	install -Dm644 files/fcron.pam "$subpkgdir/etc/pam.d/fcron"
	install -Dm644 files/fcrontab.pam "$subpkgdir/etc/pam.d/fcrontab"
}

sha512sums="ddfd3e3a297b843c924aacccffaa5c1c6b300497f39daa1cdb90dc4cf4bc757042b0b2c1f055c119c8128c64d830ee0e8757091610432f5ffcacca25d369e5cd  fcron-3.2.1.src.tar.gz
e0abf7da0a9c1c2a8791f9f5b8cdb99260ac3bc49b0e4906ec3fb0d3344f8fe3819a7a80b1bc7b463fe4bc4499686e84ebb33aef9a0ec2298855b06340723e43  systab.orig
f87c9c9664611cd529b5f46affe5c3ff7af8fd2800b74958c34730a5ca564d888b5ddbfe18fa1ee20d4e26ed800ca38ed7f9626dd39ca2d3fc930be1ad78f4c5  fcron.initd"
